IdeaBlade DevForce 2010 Help Reference
EntityListManager<T> Constructor(EntityManager,Predicate<T>,EntityProperty[],IList,Boolean)
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityListManager<T> Class > EntityListManager<T> Constructor : EntityListManager<T> Constructor(EntityManager,Predicate<T>,EntityProperty[],IList,Boolean)



entityManager
EntityManager holding the Entities
filter
A predicate returning true if the tested entity belongs in the list
filterProperties
The watched properties. If supplied, changes to values in the watched properties trigger filtering. If null, any changes to Entities of this type will trigger filtering.
list
The list to be managed
shouldRefresh
If true, immediately refresh the list for the filtering criteria
Initialize a new instance of the EntityListManager.

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal entityManager As EntityManager, _
   ByVal filter As Predicate(Of T), _
   ByVal filterProperties() As EntityProperty, _
   ByVal list As IList, _
   ByVal shouldRefresh As Boolean _
)
Visual Basic (Usage)Copy Code
Dim entityManager As EntityManager
Dim filter As Predicate(Of T)
Dim filterProperties() As EntityProperty
Dim list As IList
Dim shouldRefresh As Boolean
 
Dim instance As New EntityListManager(Of T)(entityManager, filter, filterProperties, list, shouldRefresh)
C# 
public EntityListManager<T>( 
   EntityManager entityManager,
   Predicate<T> filter,
   EntityProperty[] filterProperties,
   IList list,
   bool shouldRefresh
)
C++/CLI 
public:
EntityListManager<T>( 
   EntityManager^ entityManager,
   Predicate<T^>^ filter,
   array<EntityProperty^>^ filterProperties,
   IList^ list,
   bool shouldRefresh
)

Parameters

entityManager
EntityManager holding the Entities
filter
A predicate returning true if the tested entity belongs in the list
filterProperties
The watched properties. If supplied, changes to values in the watched properties trigger filtering. If null, any changes to Entities of this type will trigger filtering.
list
The list to be managed
shouldRefresh
If true, immediately refresh the list for the filtering criteria

Example

C#Copy Code
// Example showing how a List<T> can be managed as a live list.
  public void EntityListManagerSample() {

  DomainModelEntityManager mgr = new DomainModelEntityManager();
  
  // Retrieve a customer and employee.
  var customer = mgr.Customers.FirstOrDefault(c => c.Id == 1);
  var employee = mgr.Employees.FirstOrDefault(e => e.Id == 1);

  // Load a List with customer's order summaries.
  var list = new List<OrderSummary>(customer.OrderSummaries);
  int orderCount = list.Count;

  // We want to watch for any new orders for this customer.
  // We can't "watch" the NavigationEntityProperty, so watch its FK. 
  var prop = OrderSummary.Customer_fk_IdEntityProperty;

  // Set up the manager.
  IListManager manager = new EntityListManager<OrderSummary>(mgr,
          os => os.Customer == customer,   // filter 
          new[] { prop },                  // watch
          list,                            // list to be managed
          false);                          // refresh now 

  // Create a new order - the list count should increment.
  OrderSummary aOrder = mgr.CreateEntity<OrderSummary>();
  aOrder.Employee = employee;
  aOrder.Customer = customer;
  aOrder.AddToManager();
 
  Assert.IsTrue(list.Count == orderCount + 1);

  // Now delete this order - the list count should decrement.
  aOrder.EntityAspect.Delete();
  Assert.IsTrue(list.Count == orderCount);
}
Visual BasicCopy Code

Remarks

The Filter uses a .NET Predicate<T>, a delegate that defines a set of criteria and determines whether the specified object passed to it meets those criteria. The Filter receives every addition, deletion or modification (based on the FilterProperties specified) of entities of the type watched, and determines whether the entity belongs in the list. If the Filter returns true the entity is added to or kept in the list; if the Filter returns false the entity is removed from the list. (Note that entities removed from the managed list are not removed from the EntityManager, nor are they deleted.)

Performance will be needlessly poor if the EntityListManager tests an entity every time any of its properties change. To avoid this, specify in the constructor or the FilterProperties property which entity properties are relevant to the filtering.

You can choose to have the EntityListManager refresh the list immediately after assuming management of the list. This is unnecessary if the supplied list is known to be complete at the time the manager is initialized.

An EntityListManager holds weak references to the Lists it watches. This means that you will need to hold on to a reference to each ELM to insure that it does not go out of scope and get garbage collected. One approach to this is to use Lists that implement the IdeaBlade.Core.IHasListManager interface. This will insure each list keeps a reference to its ELM and any shared ELM's will not go out of scope until the last of their child lists do.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.